package com.pms.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pms.pojo.EmployeeDept;
import com.pms.pojo.InfoEmployee;
import com.pms.pojo.PageVo;
import com.pms.service.EmployeeDepartmentService;

import cn.itcast.utils.Page;



@Controller
@RequestMapping("/infoemployee")
public class EmployeeInfoController {
   
	@Autowired
	private EmployeeDepartmentService  employeeDepartment;
	
	@RequestMapping("/list")
	public String list(PageVo vo,Model model) throws Exception{
		
		//
		List<EmployeeDept> departmentList = employeeDepartment.findDepartmentAll();
		model.addAttribute("department", departmentList);
		
		if(vo.getPage() == null) {//没有页面信息时从第一页显示
    		vo.setPage(1);
    	}

    	vo.setStart((vo.getPage() - 1) * vo.getSize() );//页面开始下标
    	

		List<InfoEmployee> employeeList = employeeDepartment.findEmployeeAll(vo);//根据页面传入的页数信息查询范围内所有人员信息
		
		int count = employeeDepartment.findEmployeeCount();
		
		Page<InfoEmployee> page = new Page<InfoEmployee>();
    	page.setTotal(count);       
    	page.setSize(vo.getSize());//存入每页显示条数
    	page.setPage(vo.getPage());//存入显示页数
    	page.setRows(employeeList);//存入查出的信息
    	model.addAttribute("page", page);
		
		
		return "employee_information_center";
	}
	
	//
	@RequestMapping("/find")
	public String select(PageVo vo,Model model) throws Exception{
		//
		List<EmployeeDept> departmentList = employeeDepartment.findDepartmentAll();
		model.addAttribute("department", departmentList);
    	
		List<InfoEmployee> findEmployeeSelect = employeeDepartment.findEmployeeSelect(vo);
		model.addAttribute("employeeList", findEmployeeSelect);
			
		return "employee_information_centerSelect";
	}
}
